package com.yingside.io.io;

import java.io.*;

public class TestInputStreamReader {
    public static void main(String[] args) {
        System.out.println("请输入内容:");
        // 通过标准流获取的是字节流
        InputStream in = System.in;
        // 通过字节流来获取console里面的字符串并不方便
        // 最好直接把获取的字节流转换为字符流
        // 这个就需要转换流
        // 把字节流转换为了字符流
        InputStreamReader inputStreamReader = new InputStreamReader(in);

        // 为了更加方便的获取内容，我们可以在转换流上面套上处理流
        BufferedReader br = null;
        br = new BufferedReader(inputStreamReader);

        Writer writer = null;
        PrintWriter pw = null;

        String str = null;

        try {
            writer = new FileWriter("images/TestJFram.txt");

            pw = new PrintWriter(writer);


            while((str = br.readLine()) != null){
                if(str.trim().equals("exit")){
                    break;
                }
                System.out.println("str = " + str);
                pw.println(str);

            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

            pw.close();
        }
    }
}
